#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
int n, m, h; 
 void check(int& a, int& b, auto vec) {
    a = 0, b = 0;
    int cnt = 0;
    for(auto x : vec) {
        if(cnt + x > h) break;
        cnt += x;
        a++;
        b += cnt;
    }
 }

void solve() {
    cin >> n >> m >> h;
    int p = 1;
    vector<int> a(m);
    for(int i = 0; i < m; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int x = 0, y = 0;
    check(x, y, a);
    // cout << x << ' ' << y << endl;
    pii pa = {x, y};
    for(int i = 1; i < n; i++) {
        for(int i = 0; i < m; i++) cin >> a[i];
        sort(a.begin(), a.end());
        check(x, y, a);
        // cout << x << ' ' << y << endl;
        if(x > pa.first) {
            p++;
        }else if(x == pa.first && y < pa.second) p++;
    }
    cout << p << endl;
}

signed main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}